
const getDefaultState = () => {
  return {
    realName:  uni.getStorageSync('realName') || null,
    userName:   uni.getStorageSync('userName') || null,
    typeId:  uni.getStorageSync('typeId') || null,
    ossBucketHost: uni.getStorageSync('ossBucketHost') || '',
    isEgg:  uni.getStorageSync('isEgg') || '3', // 默认不产奶不产蛋 2 产奶 1产蛋 3 奶蛋不产
    kind:  uni.getStorageSync('kind') || '' //  用户养殖的类型 1鸡 2鸭 3牛 4 羊 5马 6猪
  }
}

const state = getDefaultState()

const mutations = {

  SET_REALNAME: (state, realName) => {
    state.realName = realName
  },
  SET_USERNAME: (state, userName) => {
    state.userName = userName
  },
  SET_TYPEID: (state, typeId) => {
    state.typeId = typeId
  },
  SET_OSS: (state, ossBucketHost) => {
    state.ossBucketHost = ossBucketHost
  },
  SET_EGG: (state, val) => {
    state.isEgg = val
  },
  SET_KIND: (state, val) => {
    state.kind = val
  }
}

const actions = {

  setRealName({commit},val){
    uni.setStorageSync('realName', val)
    commit('SET_REALNAME',val)
  },
  setUserName({commit},val){
    uni.setStorageSync('userName', val)
    commit('SET_USERNAME',val)
  },

  
  setTypeId({commit},val){
    uni.setStorageSync('typeId', val)
    commit('SET_TYPEID',val)
  },
  setossBucketHost({commit},val){
    uni.setStorageSync('ossBucketHost', val)
    commit('SET_OSS',val)
  },
  setEgg({commit},val){
      // 用户养殖的类型 1鸡 2鸭 3牛 4 羊 5马 6猪
      if(val==1||val==2){
        uni.setStorageSync('isEgg', '1')
        commit('SET_EGG','1')
      }else if(val==3|| val==4||val==5){
        uni.setStorageSync('isEgg', '2')
        commit('SET_EGG','2')
      }else{
        uni.setStorageSync('isEgg', '3')
        commit('SET_EGG','3')
      }
  },

  setKind({commit},val){
    // 用户养殖的类型 1鸡 2鸭 3牛 4 羊 5马 6猪
    uni.setStorageSync('kind', val)
    commit('SET_KIND',val)
},

  

}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}